package com.sinopec.basemodule.view.nodata

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.sinopec.basemodule.R
import com.sinopec.basemodule.constants.NoDataTypeEnum
import com.sinopec.basemodule.utils.ARouterManagerUtils
import kotlinx.android.synthetic.main.bm_f_no_data.*

/**
 * 类描述：无数据展示界面<br/>
 * 创建人：吴冬冬<br/>
 * 创建时间：2019/9/20 17:20 <br/>
 */
@Route(path = ARouterManagerUtils.GOTO_BM_NO_DATA_FRAGMENT)
class NoDataFragment : Fragment() {
    private val mImageResourceId by lazy {
        arguments?.getInt("imageResourceId", NoDataTypeEnum.NULL.imageResourceId)
                ?: throw IllegalArgumentException("NoDataFragment传出参数错误请检查")
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.bm_f_no_data, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mIv.setImageResource(mImageResourceId)
    }

    /**
     * 重新设置iv显示
     */
    fun setImageResource(typeEnum: NoDataTypeEnum) {
        val newImageResourceId = typeEnum.imageResourceId
        if (mImageResourceId == newImageResourceId) {
            return
        }
        mIv.setImageResource(newImageResourceId)
    }
}